package cn.szzsi.validator;

import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Brand;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * Created by haotian on 2016/9/26.
 */
public class BusinessBrandValidator extends Validator {

    @Override
    protected void validate(Controller c) {
        validateRequiredString("brand.name", "nameMessages", "品牌名称不允许为空!");
        validateUrl("brand.url", "urlMessages", "网址格式错误!");
        validateRequiredString("brand.orderList", "orderListMessages", "排序不允许为空!");

        validateInteger("brand.orderList", 0, 100, "orderListMessages", "排序必须为零或正整数!");
    }

    @Override
    protected void handleError(Controller c) {
        c.keepModel(Brand.class);
        c.render(CommonUtil.TEMPLATE_PATH+"/business/brand/brand_input.html");
    }
}